package com.xmbandu.app.utils;

import android.os.Handler;
import android.os.Looper;

public class ThreadUtils {

    static final Handler UI_HANDLER = new Handler(Looper.getMainLooper());

    public static void postOnUI(Runnable r) {
        if (isUiThread()) {
            r.run();
        } else {
            UI_HANDLER.post(r);
        }
    }

    public static void postDelayOnUI(Runnable r, long delayMillis) {
        UI_HANDLER.postDelayed(r, delayMillis);
    }

    public static boolean isUiThread() {
        final Looper myLooper = Looper.myLooper();
        final Looper mainLooper = Looper.getMainLooper();
        return mainLooper.equals(myLooper);
    }
}
